package pcmd_conn_base;

use strict;
use warnings;


#---------------------------------
# New: constructor of the class --
#---------------------------------
sub new {
    my $arg0 = shift;
    my $cls = ref($arg0) || $arg0;
    
    my $self = {};
    bless $self, $cls;

    $self->init(@_);
    
    return $self;
}


#--------------------------
# Init: Initialize class --
#--------------------------
sub init {
    my $self = shift;
    
    $self->{directories} = {};
    $self->{state} = "disconnected";
    $self->{root_dir} = "";
};


#-----------
# Connect --
#-----------
sub connect {
    my $self = shift;
    
    return "Not yet implemented";
};


#--------------
# Disconnect --
#--------------
sub disconnect {
    my $self = shift;
    
    return "Not yet implemented";
};


#-----------------
# Get file list --
#-----------------
sub get_file_list {
    my $self = shift;
    my $directory = shift;
    my $sort_base = shift;
    my $array = shift;
    
    unless ($self->is_connected()) { return 'Not connected'; };
    
    if ($self->is_opened($directory)) {
        push(@{$array}, $self->get_directory($directory)->get_file_list($sort_base));
    } else {
        my $error = $self->open_directory($directory);
        unless ($error) {
            push(@{$array}, @{$self->get_directory($directory)->get_files($sort_base)});
        } else {
            return $error;
        };
    };    
    
    return 0;
};


#------------------
# Open directory --
#------------------
sub open_directory {
    my $self = shift;
    my $path = shift;    
    
    return "Not yet implemented";
};


#----------------
# Get directory --
#----------------
sub get_directory {
    my $self = shift;
    my $path = shift;
    
    return $self->{directory}{$path};
};


#----------------
# Get root dir --
#----------------
sub get_root_dir {
    my $self = shift;

    return $self->{root_dir};
};


#--------------
# Is opened  --
#--------------
sub is_opened {
    my $self = shift;
    my $path = shift;
    
    return (defined $self->{directory}{$path});
};


#----------------
# Is connected --
#----------------
sub is_connected {
    my $self = shift;
    
    return ($self->{state} eq 'connected');
};


1;
